package cn.tedu.onlinestore.order.controller;

import cn.tedu.onlinestore.base.response.JsonResult;
import cn.tedu.onlinestore.order.pojo.dto.OrderParam;
import cn.tedu.onlinestore.order.pojo.vo.OrderVO;
import cn.tedu.onlinestore.order.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/v1/order/")
public class OrderController {
    @Autowired
    OrderService orderService;
    @PostMapping("create")
    public JsonResult createOrder(OrderParam orderParam) {
        log.debug("开始处理创建订单请求:{}",orderParam);
        orderService.create(orderParam);
        return JsonResult.ok();
    }

    @GetMapping("list")
    public JsonResult list(OrderParam orderParam) {
        log.debug("开始处理查询订单列表请求");
        List<OrderVO> list = orderService.list(orderParam);
        return JsonResult.ok(list);
    }

    @PostMapping("cancel")
    public JsonResult cancel(OrderParam orderParam) {
        log.debug("开始处理取消订单请求");
        orderService.cancel(orderParam);
        return JsonResult.ok();
    }
}
